//
//  SN_QuestionCollect_TableViewCell.m
//  Shiyun_Newspaper
//
//  Created by zz on 17/6/26.
//  Copyright © 2017年 ShiYun. All rights reserved.
//

#import "SN_QuestionCollect_TableViewCell.h"

@interface SN_QuestionCollect_TableViewCell()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *questionImageView;
@property (nonatomic, strong) UILabel *timeLabel;

@property (nonatomic, strong) UIView *grayView;

@end

@implementation SN_QuestionCollect_TableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 12, 300, 15)];
        _titleLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_titleLabel];
        
        _questionImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_titleLabel.frame) + 16, SCREENWIDTH - 30, 90)];
        _questionImageView.contentMode = UIViewContentModeScaleAspectFill;
        _questionImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:_questionImageView];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_questionImageView.frame) + 13, 200, 14)];
        _timeLabel.font = [UIFont systemFontOfSize:14];
        _timeLabel.textColor = [UIColor colorWithHexString:@"#979797"];
        [self.contentView addSubview:_timeLabel];
        
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        _deleteButton.layer.borderWidth = 0.5;
        _deleteButton.layer.borderColor = [UIColor colorWithHexString:@"#fb524a"].CGColor;
        _deleteButton.frame = CGRectMake(SCREENWIDTH - 50 - 15, CGRectGetMaxY(_questionImageView.frame) + 10, 50, 24);
        [_deleteButton setTitleColor:[UIColor colorWithHexString:@"#fb524a"] forState:UIControlStateNormal];
        _deleteButton.layer.cornerRadius = 6;
        _deleteButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_deleteButton];
        
        _grayView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_deleteButton.frame) + 8, SCREENWIDTH, 10)];
        _grayView.backgroundColor = [UIColor colorWithHexString:@"#f4f5f7"];
        [self.contentView addSubview:_grayView];
    }
    
    return self;
}


- (void)setModel:(SN_Question_Solve_Model *)model {
    
    _model = model;
    
    NSString *title = [NSString stringWithFormat:@"%@%@ %@第%ld期",model.editiontypename,model.gradername,model.coursename,(long)model.phase];
    
    
    _titleLabel.text = title;
    
    NSURL *questionUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",PICPERFIXURL,model.problempic]];
    
    [_questionImageView sd_setImageWithURL:questionUrl];
    
    _timeLabel.text = [model.jointime substringToIndex:10];
}

@end
